//
//  ZZCPlayingView.m
//  B段项目
//
//  Created by dllo on 15/12/22.
//  Copyright © 2015年 张智超. All rights reserved.
//

#import "ZZCPlayingView.h"

@implementation ZZCPlayingView

-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self createSubView];
    }
    return self;
}


- (void)createSubView{
    
    //音乐图片(中间的那个大图)
    self.musicImage = [[UIImageView alloc]init];
    [self addSubview:self.musicImage];
    [self.musicImage mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.top.left.mas_equalTo(WIDTH / 8);
        make.width.mas_equalTo(WIDTH * 0.75);
        make.height.mas_equalTo(WIDTH * 0.75);
    }];
    
    //音乐标题
    self.musicTitle = [[UILabel alloc]init];
    //设置字体大小并居中
    self.musicTitle.font = [UIFont systemFontOfSize:22];
    self.musicTitle.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.musicTitle];
    [self.musicTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(WIDTH / 8);
        make.top.equalTo(self.musicImage.mas_bottom).offset(20);
        make.width.mas_equalTo(WIDTH * 0.75);
        make.height.mas_equalTo(30);
    }];
    
    //单曲按钮
    self.danQuButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.danQuButton setImage:[UIImage imageNamed:@"iconfont-danquxunhuan.png"] forState:UIControlStateNormal];
    [self addSubview:self.danQuButton];
    [self.danQuButton mas_makeConstraints:^(MASConstraintMaker *make) {
       
        make.left.mas_equalTo(WIDTH / 4);
        make.top.equalTo(self.musicTitle.mas_bottom).offset(20);
        make.width.mas_equalTo(WIDTH / 375 * 30);
        make.height.mas_equalTo(HEIGHT / 667 * 30);
    }];
    
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"playMode"] isEqualToString:@"单曲循环"]) {
        
        [self.danQuButton setImage:[UIImage imageNamed:@"iconfont-danquxunhuan-2.png"] forState:UIControlStateNormal];
    }else{
        [self.danQuButton setImage:[UIImage imageNamed:@"iconfont-danquxunhuan.png"] forState:UIControlStateNormal];
    }
    
    
    //随机播放按钮
    self.suiJiButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.suiJiButton setImage:[UIImage imageNamed:@"iconfont-suijibofang.png"] forState:UIControlStateNormal];
    [self addSubview:self.suiJiButton];
    [self.suiJiButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.danQuButton.mas_right).offset(WIDTH / 6);
        make.top.equalTo(self.musicTitle.mas_bottom).offset(20);
        make.width.mas_equalTo(WIDTH / 375 * 30);
        make.height.mas_equalTo(HEIGHT / 667 * 30);
    }];
    
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"playMode"] isEqualToString:@"随机播放"]) {
        
        [self.suiJiButton setImage:[UIImage imageNamed:@"iconfont-suijibofang-2.png"] forState:UIControlStateNormal];
    }else{
        [self.suiJiButton setImage:[UIImage imageNamed:@"iconfont-suijibofang.png"] forState:UIControlStateNormal];
    }
    
    //列表循环按钮
    self.ListButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.ListButton setImage:[UIImage imageNamed:@"iconfont-liebiaoxunhuan.png"] forState:UIControlStateNormal];
    [self addSubview:self.ListButton];
    [self.ListButton mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.equalTo(self.suiJiButton.mas_right).offset(WIDTH / 6);
        make.top.equalTo(self.musicTitle.mas_bottom).offset(20);
        make.width.mas_equalTo(WIDTH / 375 * 30);
        make.height.mas_equalTo(HEIGHT / 667 * 30);
    }];
    
    if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"playMode"] isEqualToString:@"顺序播放"]) {
        
        [self.ListButton setImage:[UIImage imageNamed:@"iconfont-liebiaoxunhuan-2.png"] forState:UIControlStateNormal];
    }else{
        [self.ListButton setImage:[UIImage imageNamed:@"iconfont-liebiaoxunhuan.png"] forState:UIControlStateNormal];
    }
    
    //进度条
    self.musicSlider = [[UISlider alloc]initWithFrame:CGRectMake(self.frame.origin.x / 7 * 2, self.frame.size.height / 40 * 37, self.frame.origin.x / 7 * 3, 10)];
    //创建一个image替换系统小球
    UIImage *slImage = [UIImage imageNamed:@"heikuai.png"];
    [self.musicSlider setThumbImage:slImage forState:UIControlStateNormal];
    //进度条左侧颜色
    self.musicSlider.minimumTrackTintColor = [UIColor colorWithRed:60/255.0 green:60/255.0 blue:60/255.0 alpha:1.0];
    //进度条右侧颜色
    self.musicSlider.maximumTrackTintColor = [UIColor colorWithRed:200/255.0 green:200/255.0 blue:200/255.0 alpha:1.0];
    [self addSubview:self.musicSlider];
    
    //总时长
    self.zongTime = [[UILabel alloc]init];
    self.zongTime.frame = CGRectMake(self.musicSlider.frame.origin.x - 40 * WIDTH / 375, self.musicSlider.frame.origin.y - 30 * HEIGHT / 667 / 3 , 40 * WIDTH / 375 , 30 * HEIGHT / 667);
    self.zongTime.font = [UIFont systemFontOfSize:12];
    self.zongTime.text = @"00:00";
    [self addSubview:self.zongTime];
    
    //音频剩余时长Label
    self.remainTime = [[UILabel alloc]initWithFrame:CGRectMake(self.musicSlider.frame.origin.x + self.musicSlider.frame.size.width + 5, self.musicSlider.frame.origin.y - 30 * HEIGHT / 667 / 3, 80 * WIDTH / 375, 30 * HEIGHT / 667)];
    
    self.remainTime.font = [UIFont systemFontOfSize:12];
    self.remainTime.text = @"00:00";
    [self addSubview:self.remainTime];
    
}

-(void)setPlayModel:(ZZCPlayListModel *)playModel{
    _playModel = playModel;
    
    [self.musicImage sd_setImageWithURL:self.playModel.imgUrl placeholderImage:PLACEHOLDER_IMAGE];
    self.musicTitle.text = self.playModel.title;
    
}



/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
